﻿@model SnippetBox.Web.Models.UserProfileModel

@{
    ViewBag.Title = @Model.User.Username + " Profile";
}
<div id="profilePage">
    <h1>
        @Model.User.Username

        @if (Model.IsMyProfile) { <a href="@Url.RouteUrl("User-Edit", new { username = Model.User.Username })" class="lightButton">Edit Profile</a> }
        @if (Model.HasWebsiteLink) { <a href="@Model.User.Website" class="link" rel="nofollow" target="_blank">website</a> }
        @if (Model.HasTwitterLink) { <a href="@Model.TwitterUrl" class="link" rel="nofollow" target="_blank">twitter</a> }
    </h1>
    
    <aside class="information">
        <span class="bold">@Model.User.Username</span> has been a 
        <span title="@Model.User.DateCreated">member for @Model.User.DateCreated.ToRelativeDate(prefix: "", suffix:"")</span>, 
        have <span>@Model.User.Favorites.Count snippets as favorites</span> 
        and has <span>created @Model.User.Snippets.Count snippets</span>.
    </aside>   
     
     @if (TempData.ContainsKey("message")) {
    <aside class="message">
        @TempData["message"]
    </aside>
     }

    <div class="column2">
        <h2>My Snippets</h2>
        
        @if (Model.MySnippets.Count == 0) { 
            <span class="light">@Model.User.Username hasn't created any snippets yet.</span>
        }
        <div id="mySnippets" class="border">        
            @Html.DisplayFor(m => m.MySnippets)
        </div>

        @if (Model.MySnippets.HasNextPage) {
            <a href="?snippetsPage=@(Model.MySnippets.PageNumber + 1)" data-append-to="mySnippets" data-page="@Model.MySnippets.PageNumber" data-url="?snippetsPage={0}" data-page-count="@Model.MySnippets.PageCount" id="snipPaging" class="infyPaging">load more snippets</a>
        }
    </div>

    <div class="column2">
        <h2>My Favorites</h2>

        @if (Model.MyFavorites.Count == 0) { 
            <span class="light">@Model.User.Username has no favorites yet.</span>
        }
        <div id="myFavorites">
            @Html.DisplayFor(m => m.MyFavorites)
        </div>

        @if (Model.MyFavorites.HasNextPage){
            <a href="?favoritesPage=@(Model.MyFavorites.PageNumber + 1)" data-append-to="myFavorites" data-page="@Model.MyFavorites.PageNumber" data-url="?favoritesPage={0}" data-page-count="@Model.MyFavorites.PageCount" id="favPaging" class="infyPaging">load more snippets</a>
        }
    </div>


</div>
<script type="text/javascript">
    $(function () {
        snippetBox.profile.init();
    });
</script>
 